home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / v3 / sim.lha / sim / builtin / meta.c < prev    next >
C/C++ Source or Header  |  1990-04-12  |  3KB  |  146 lines

  1. /************************************************************************
  2. *                                    *
  3. * The SB-Prolog System                            *
  4. * Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987    *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24. /* meta.c */
  25.  
  26. #include "builtin.h"
  27.  
  28. extern double floatval();
  29. extern LONG   makefloat();
  30.  
  31. b_VAR()
  32. {
  33.    register LONG     op;
  34.    register LONG_PTR top;
  35.  
  36.    op = reg[1];  DEREF(op);
  37.    if (ISNONVAR(op))
  38.       {FAIL0;}
  39. }
  40.  
  41. b_NONVAR()
  42. {
  43.    register LONG     op;
  44.    register LONG_PTR top;
  45.  
  46.    op = reg[1];  DEREF(op);
  47.    if (ISVAR(op))
  48.       {FAIL0;}
  49. }
  50.  
  51. b_ATOM()
  52. {
  53.    register LONG     op;
  54.    register LONG_PTR top;
  55.  
  56.    op = reg[1];  DEREF(op);
  57.    if (!ISATOM(op))
  58.       {FAIL0;}
  59. }
  60.  
  61. b_ATOMIC()
  62. {
  63.    register LONG     op;
  64.    register LONG_PTR top;
  65.  
  66.    op = reg[1];  DEREF(op);
  67.    if (!(ISNUM(op) || ISATOM(op)))
  68.       {FAIL0;}
  69. }
  70.  
  71. b_INTEGER()
  72. {
  73.    register LONG     op;
  74.    register LONG_PTR top;
  75.  
  76.    op = reg[1];  DEREF(op);
  77.    if (!ISINTEGER(op))
  78.       {FAIL0;}
  79. }
  80.  
  81. b_REAL()
  82. {
  83.    register LONG     op;
  84.    register LONG_PTR top;
  85.  
  86.    op = reg[1];  DEREF(op);
  87.    if (!ISFLOAT(op))
  88.       {FAIL0;}
  89. }
  90.  
  91. b_STRUCTURE()
  92. {
  93.    register LONG     op;
  94.    register LONG_PTR top;
  95.  
  96.    op = reg[1];  DEREF(op);
  97.    if (!(ISLIST(op) || (ISCONSTR(op) && GET_STR_ARITY(op) != 0)))
  98.       {FAIL0;}
  99. }
  100.  
  101. b_TERMREP()    /* reg1 is term (var);  reg2 is integer that is its rep */
  102. {
  103.    register LONG     op;
  104.    register LONG_PTR top;
  105.  
  106.    op = reg[1];  DEREF(op);
  107.    if (!unify(MAKEINT(op), reg[2]))
  108.       {FAIL0;}
  109. }
  110.  
  111. b_DBREF()
  112. {
  113.     register LONG op;
  114.     register LONG_PTR top;
  115.     PSC_REC_PTR psc_ptr;
  116.  
  117.     op = reg[1]; DEREF(op);
  118.     if (TAG(op) == CS_TAG) {
  119.     psc_ptr = GET_STR_PSC(op);
  120.     if (GET_ETYPE(psc_ptr) != T_BUFF) {FAIL0;}
  121.     }
  122.     else {FAIL0;}
  123. }    
  124.  
  125. b_FLOOR0()    /* F, I, N */
  126. {
  127. /* reg3 is bound to a number which gives the direction of conversion:
  128.  * if reg3 = 0 then reg1 is bound to a number and reg2 is a variable;
  129.  * while if reg3 = 1 then reg1 is a variable and reg2 is bound to a number.
  130.  * No checking for the above is done.
  131.  */
  132.     register LONG     op1, op2, op3;
  133.     register LONG_PTR top;
  134.  
  135.     op1 = reg[1];  DEREF(op1);
  136.     op2 = reg[2];  DEREF(op2);
  137.     op3 = reg[3];  DEREF(op3);
  138.     if (INTVAL(op3) == 0) {    /* reg1 = number, reg2 = free */
  139.        FOLLOW(op2) = MAKEINT((LONG)(NUMVAL(op1)));
  140.        PUSHTRAIL(op2);
  141.     } else {                   /* reg1 = free, reg2 = number */
  142.        FOLLOW(op1) = makefloat((double)(NUMVAL(op2)));
  143.        PUSHTRAIL(op1);
  144.     }
  145. }
  146.